// UserPages.h: interface for the CUserPages class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_USERPAGES_H__70CA284F_C478_480B_9A1D_3FB38EF67F6A__INCLUDED_)
#define AFX_USERPAGES_H__70CA284F_C478_480B_9A1D_3FB38EF67F6A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Pages.h"
#include "User.h"
#include "KDcom.h"
extern KDcom theDcom;

class CUserPages : public CPages<CUser>
{
public:
	enum FindUserInfoMode
	{
		FUIM_ALL		= -1,
		FUIM_USERNAME	= 0,
		FUIM_DESCRIPTION= 1,
		FUIM_TOKENSN	= 2,
	};
#define COL_USER_NAME			"UserName"
#define COL_USER_DESCRIPTION	"UserDesc"
#define COL_USER_TOKENSN		"TokenSn"
#define COL_USER_GROUP			"Dept"
	int FindUserInfo(FindUserInfoMode findmode, const CString &strFoundText)
	{
		const int iSaveCurrentPageNo= m_upCurrentPage.m_ulPageNo;
		int iUserShownIndex= -1;
		for (ULONG ulPageNo= m_MIN_PAGE_NO; ulPageNo <= m_ulMaxPageNo;	ulPageNo++)
		{
			GoPage( ulPageNo );
			for (int iUserIndex= 0; iUserIndex < m_upCurrentPage.m_arrItems.GetSize(); iUserIndex++)
			{
				CString strText;
				CUser &user= m_upCurrentPage.m_arrItems[iUserIndex];
				switch (findmode)
				{
				default:
					return (iUserShownIndex);
				case FUIM_USERNAME:
					strText = user.m_strUserName;
					break;
				case FUIM_DESCRIPTION:
					strText = user.m_strDesc;
					break;
				case FUIM_TOKENSN:
					strText = user.m_strSn;
					break;
				}
				if (FUIM_USERNAME == findmode)
				{
					if (strText == strFoundText)
					{
						iUserShownIndex = iUserIndex;
						break;
					}
				} 
				else
				{
					if (strText.Find( strFoundText, 0 ) >= 0)
					{
						iUserShownIndex = iUserIndex;
						break;
					}
				}
			}
			if (iUserShownIndex > -1)
				break;
		}
		
		if (-1 == iUserShownIndex)
		{
			GoPage( iSaveCurrentPageNo );
		}

		return (iUserShownIndex);
	}

	CUserPages()
	{
		m_filter.m_strSearchTable = "KOperators";
	}

	CUserPages(const CString &strGroup)
		: m_strGroup(strGroup)
	{
		m_filter.m_strSearchTable = "KOperators";
		m_filter.m_strFilter = CString(COL_USER_GROUP) + "='"+ strGroup +"'";
	}

	virtual ~CUserPages()
	{}

	virtual ULONG ReadCurrentPageItems(ULONG ulPageNo)
	{
		if (CPages<CUser>::ReadCurrentPageItems() > 0)
		{
			for (int i= 0; i < m_upCurrentPage.m_arrItems.GetSize(); i++)
			{
				m_upCurrentPage.m_arrItems[i].m_strGroup = m_strGroup;
			}
		}
		return (m_upCurrentPage.m_arrItems.GetSize());
	}
	
	CString m_strGroup;
};

#endif // !defined(AFX_USERPAGES_H__70CA284F_C478_480B_9A1D_3FB38EF67F6A__INCLUDED_)
